<%@ page contentType="text/html" %>
<%@ taglib prefix="jbfilter" uri="http://jbfilter.org/tag" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:useBean id="dao" class="org.jbfilter.test.beans.factory.DataAccessObject" scope="application"/>
<c:set var="datePattern" value="dd/MM/yyyy"/>
<c:set var="checked">checked="checked"</c:set>
<c:set var="selected">selected="selected"</c:set>
<c:set var="truncateClass" value="org.jbfilter.core.TruncateUnit"/>

<html>
<head>
<title>StartEndDateFilterComponent</title>
</head>
<body>

<jbfilter:filter id="myFilterStartEndDate" providerName="bean" clean="${param.clean}">
	<jbfilter:startEndDateComponent
		id="fc"
		propertyPath="${param.propertyPath}"
		startDate="${param.startDate}"
		endDate="${param.endDate}"
		pattern="${datePattern}"
		inverted="${param.inverted}"
		enabled="${!param.disabled}"
		nullTestingEnabled="${param.nullTestingEnabled}"
		valueForNull="${param.valueForNull}"
		truncate="${param.truncate}"
		var="comp"
		/>
</jbfilter:filter>
<c:choose>
	<c:when test="${param.includeBorders}">
		<jbfilter:filter id="myFilterStartEndDate">
			<jbfilter:startEndDateComponent
				id="fc"
				includeBorders="${param.includeBorders}"
				/>
		</jbfilter:filter>
	</c:when>
	<c:otherwise>
		<jbfilter:filter id="myFilterStartEndDate">
			<jbfilter:startEndDateComponent
				id="fc"
				includeBorderStartDate="${param.includeBorderStartDate}"
				includeBorderEndDate="${param.includeBorderEndDate}"
				/>
		</jbfilter:filter>
	</c:otherwise>
</c:choose>

<form action="">
	<table>
		<tr>
			<td>propertyPath</td>
			<td>
				<select name="propertyPath">
					<option value="born"<c:if test="${comp.propertyPath == 'born'}"> ${selected}</c:if>>born</option>
					<option value="died"<c:if test="${comp.propertyPath == 'died'}"> ${selected}</c:if>>died</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>startDate</td>
			<td><input type="text" name="startDate" value="<fmt:formatDate value="${comp.startDate}" pattern="${datePattern}"/>"/></td>
		</tr>
		<tr>
			<td>endDate</td>
			<td><input type="text" name="endDate" value="<fmt:formatDate value="${comp.endDate}" pattern="${datePattern}"/>"/></td>
		</tr>
		<tr>
			<td>truncate</td>
			<td>
				<select name="truncate">
					<option value="">N/A</option>
					<jbfilter:forEachEnum enumClass="${truncateClass}" var="curr">
						<option value="${curr}"<c:if test="${comp.truncate == curr}">selected="selected"</c:if>>${curr}</option>
					</jbfilter:forEachEnum>
				</select>
			</td>
		</tr>
		<tr>
			<td>valueForNull </td>
			<td><input type="text" name="valueForNull" value="${param.valueForNull}"/></td>
		</tr>
		<tr>
			<td>includeBorderStartDate</td>
			<td><input type="checkbox" name="includeBorderStartDate" value="true"<c:if test="${comp.includeBorderStartDate}"> ${checked}</c:if>/>includeBorderStartDate</td>
		</tr>
		<tr>
			<td>includeBorderEndDate</td>
			<td><input type="checkbox" name="includeBorderEndDate" value="true"<c:if test="${comp.includeBorderEndDate}"> ${checked}</c:if>/>includeBorderEndDate</td>
		</tr>
		<tr>
			<td>includeBorders</td>
			<td><input type="checkbox" name="includeBorders" value="true"<c:if test="${comp.includeBorderStartDate && comp.includeBorderEndDate}"> ${checked}</c:if>/>includeBorders</td>
		</tr>
		<tr>
			<td>inverted</td>
			<td><input type="checkbox" name="inverted" value="true"<c:if test="${comp.inverted}"> ${checked}</c:if>/>inverted</td>
		</tr>
		<tr>
			<td>disabled</td>
			<td><input type="checkbox" name="disabled" value="true"<c:if test="${!comp.enabled}"> ${checked}</c:if>/>disabled</td>
		</tr>
		<tr>
			<td>nullTestingEnabled</td>
			<td><input type="checkbox" name="nullTestingEnabled" value="true"<c:if test="${comp.nullTestingEnabled}"> ${checked}</c:if>/>nullTestingEnabled</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>
				<input type="submit" value="Ok"/>
				<input type="submit" name="clean" value="Clean"/>
			</td>
		</tr>
	</table>
</form>

<jbfilter:doFilter
	filterId="myFilterStartEndDate"
	items="${dao.allComposers}"
	varFilteredItems="filteredComposers"/>

<table border="1">
	<thead>
		<tr>
			<td>id</td>
			<td>Name</td>
			<td>born</td>
			<td>died</td>
			<td>country</td>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${filteredComposers}" var="composer">
			<tr>
				<td>${composer.id}</td>
				<td>${composer.name}</td>
				<td><fmt:formatDate value="${composer.born}" pattern="${datePattern}"/></td>
				<td><c:if test="${empty composer.died}">&nbsp;</c:if><fmt:formatDate value="${composer.died}" pattern="${datePattern}"/></td>
				<td>${composer.country}</td>
			</tr>
		</c:forEach>
	</tbody>
</table>
comp.propertyPath : ${comp.propertyPath}<br/>
comp.startDate : ${comp.startDate}<br/>
comp.endDate : ${comp.endDate}<br/>
comp.truncate: ${comp.truncate}<br/>
comp.inverted : ${comp.inverted}<br/>
comp.enabled : ${comp.enabled}<br/>
comp.nullTestingEnabled : ${comp.nullTestingEnabled}<br/>
comp.active : ${comp.active}<br/>
comp.includeBorderEndDate : ${comp.includeBorderEndDate}<br/>
comp.includeBorderStartDate : ${comp.includeBorderStartDate}<br/>
${comp}

</body>

</html>